﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _16_01_2013
{
    class ParamExample
    {
        public void NhapLieuMang(params int[] List)
        {
            Console.Write("Nhap vao so chieu dai cua mang: ");
            int n = Convert.ToInt32(Console.ReadLine());
            List = new int[n];
            for (int i = 0; i < n; i++)
            {
                Console.Write("\n a[{0}]: ", i);
                List[i] = Convert.ToInt32(Console.ReadLine());
            }
        }
        public int Adding_ArrayElement(params int[] List)
        {
            int Total = 0;
            foreach (int I in List)
            {
                Total += I;
            }
            return Total;
        }
        public bool SearchElement(int e,params int[] List)
        {
            //e: phan tu can tim
            bool flag = false;//gia su khong tim thay phan tu e
            foreach (int I in List)
            {
                if (e == I)
                {
                    flag = true;//tim thay
                    break;
                }
            }
            return flag;
        }
        public long CalcSumEven(params int[] List)
        {
            
            long sumeven = 0;
            foreach (int I in List)
            {
                if (I%2==0)
                {
                    sumeven += I;
                }
            }
            return sumeven;
        }
        public long CalcSumOdd1(params int[] List)
        {
            
            long sumodd = 0;
            foreach (int I in List)
            {
                if (I % 2 == 1)
                {
                    sumodd += I;
                }
            }
            return sumodd;
        }
        public long CalcSumOdd(params int[] List)
        {

            long sumodd = 0;
            for (int I = 0; I < List.Length;I++ )
            {
                if (List[I] % 2 == 1)
                {
                    sumodd += I;
                }
            }
            return sumodd;
        }
        public long SearchMax(params int[] List)
        {
            
            int max = List[0];
            foreach (int I in List)
            {
                if (max<I)
                {
                    max = I;
                }
            }
            return max;
        }
        public long SearchMin(params int[] List)
        {
         
            int min = List[0];
            foreach (int I in List)
            {
                if (min > I)
                {
                    min = I;
                }
            }
            return min;
        }
        
        public void SortArray(params int[] List)
        {
            int temp;
            for (int i = 0; i < List.Length-1; i++)
            {
                for (int j = i + 1; j < List.Length; j++)
                {
                    if (List[i] > List[j])
                    {
                        temp = List[i];
                        List[i] = List[j];
                        List[j] = temp;
                        //this.HoanViHaiSo(ref List[i], ref List[j]);
                    }
                }
            }
        }
        public void HoanViHaiSo(ref int n1, ref int n2)
        {
            int temp;
            temp = n1;
            n1 = n2;
            n2 = temp;
        }
        public  void XuatMang(params int[] List)
        {
            int i;
            for (i = 0; i < List.Length; i++)
            {
                Console.Write("{0} ", List[i]);
            }
        }
    }
}
